def knows(a, b):
    return graph[a][b]


class Solution(object):
    def findCelebrity(self, n):
        """
        :type n: int
        :rtype: int
        """
        now_id = 0
        for i in range(1, n):
            if knows(now_id, i):
                now_id = i
        for i in range(n):
            if i != now_id:
                if knows(now_id, i) or not knows(i, now_id):
                    return -1
        return now_id



data = Solution()
graph = [
    [1, 1, 0],
    [1, 1, 0],
    [1, 1, 1]
]
n = 3
print(data.findCelebrity(n))

